﻿using System;
using System.Collections.Generic;

namespace 队列模拟
{
    internal class Program
    {
        private static CurstomQueue<string> curstomQueue = new CurstomQueue<string>();

        internal static void Main(string[] args)
        {
            // Subscribe to News.
            curstomQueue.QueueChanged += CurstomQueue_QueueChanged;

            // 模拟向队列添加数据
            Random random = new Random();
            while (true)
            {
                curstomQueue.Enqueue(random.Next(1, 100).ToString()); // 添加随机数

                Console.SetCursorPosition(0, Console.CursorTop);
                Console.Write($"当前队列元素数量：{curstomQueue.Count}");

                // 模拟延迟
                System.Threading.Thread.Sleep(500);
            }
        }

        private static void CurstomQueue_QueueChanged(Queue<string> item, int cont)
        {
            if (cont >= 10)
            {
                Console.WriteLine();
                foreach (var item2 in item)
                {
                    Console.WriteLine(item2.ToString());
                }
                curstomQueue.Clear();
            }

            // Console.WriteLine("队列中元素数量：" + cont.ToString());
        }
    }
}
